$(function() {
		$("#left").load("../../page/common/left.html");
				var businessId= parseQueryString().businessId;
				var type=parseQueryString().type;
				var SxName = sessionStorage.getItem("SxName");
				$(".search_list #search_list h1").text(SxName);
				v_list = new Vue({
					el: '#guide-items',
					data: {
						itemsList: [],
						words: [],
						businessId:businessId,
						typr:type,
						SxName:name,
						hotWordsList:[],
						hotwords:[],
						itemsList:[]
					},
					methods: {
						getItemsList: function() {
							this.$http.get(gover.getItemsList, {
								businessId: businessId,
								type:type
							}).then(function(res) {
								//接收后端传来的数据
								doMask();
								console.log(toJson(res.data));
								if(res.data.success) {
									unMask();
									this.itemsList = res.data.data.itemsList;
								}else{
									unMask();
									showRedMsg("message", "抱歉，服务器偷懒了~");
								}
							}, function(res) {
								unMask();
								showRedMsg("message", "抱歉，服务器偷懒了~");
								console.log("获取事项出错:" + toJson(res));
							});
						},
						hotWords: function() {
							this.$http.get(guide.hotWords, {

							}).then(function(result) {
//								console.log(toJson(result.data.data))
								this.hotWordsList=result.data.data;
							}, function() {
								console.log("获取热门搜索:" + toJson(res));
								console.log('保存接口失败:' + toJson(result));
								top.$.closePopWin();

							})
						},
						search: function() {
							var search_info = $('#search-info1').val();
							search_info = search_info.replace(/^\s+|\s+$/g, "");
							this.$http.get(guide.search, {
									text:search_info
							}).then(function(result) {
								console.log(toJson(result.data.success))
								if(result.data.success==false){
									this.error();
								}else{
									console.log(toJson(result.data));
									this.hotwords=result.data.words;
									this.itemsList=result.data.data;
									$('#page1').addClass("disno");
									$('#page2').removeClass("disno");
//									this.redWords();
								}
							}, function() {
								this.error();
//								console.log("获取热门搜索:" + toJson(res));
//								console.log('保存接口失败:' + toJson(result));
//								top.$.closePopWin();

							})

						},
						error: function() {
							$(".keyword div").animate({
								"left": "0px"
							}, 200);
							$(".clean-btn").show();
							window.setTimeout(function() {
								$(".keyword div").animate({
									"left": "-1000px"
								}, 400, function() {
									$(".keyword div").css("left", "1000px")
								});
							}, 1500);
						},
						clean: function() {
							document.getElementById("search-info1").value = "";
						},
						returnPage: function() {
							$('#page2').addClass("disno");
							$('#page1').removeClass("disno");
						},
						redWords: function() {
							var words = this.hotwords;
							console.log( words.length)
							for(var i = 0; i < words.length; i++) {
								for(var j = 0; j < $('#search_list ul li').length; j++) {
									var searchInfo = $('#search_list ul li').eq(j).children("a").html();
									var keyWords = words[i];
									var reg = new RegExp("" + keyWords + "", "g");
									var result = searchInfo.replace(reg, "<span>" + keyWords + "</span>");
									$('#search_list ul li').eq(j).children("a").html(result);
								}
							}
						},
						setHotWords:function(word){
							document.getElementById("search-info1").value += word;
							$(".clean-btn").show();
						},
						//在线办理
						linkDO: function(name,itemsId,userType){
							sessionStorage.setItem('titleName',name);
								if(userType=='FWDX01'){
									userType = 'gr';
								}else if (userType=='FWDX02'){
									userType = 'fr';
								}
								window.location="../gover/readIdentityCard.html?itemsId=" + itemsId + "&userType=" + userType+"&fromGuide=1"; 
						},
						//办事指南
						linkDetail:function(itemsId,type){
							window.location="guide-detail.html?itemsId=" + itemsId + "&type=" + type; 
						}
					},
					filters: {
						titlefilter: function(val) {
							if(val != null && val.length > 43)
								val = val.substring(0, 42) + '...';
							return val;
						}
					},
					ready: function() {
						//初始化获得总页面数和列表数据
						this.hotWords();
						this.getItemsList();
						var url="../up/index.html";
						windowOpen(url);
					}
				});
				v_list.$watch('itemsList', function(val) {
					v_list.redWords();
				})
			});